package com.artqiyi.dollmachine.presenter.base;

import android.content.Context;

import com.artqiyi.dollmachine.common.Base.IBaseView;


/**
 * zhangpengcheng
 */
public class BasePresenter<V extends IBaseView, B extends BasePresenterCallback> {
    protected V mView;
    protected B mCallback;
    protected Context mContext;


    /**
     * V层的基类中赋值，用于presenter使用RxBaseCallback的时候显示加载对话框
     */
    public void setContext(Context context) {
        mContext = context;
    }

    /**
     * 设置Presenter的统一数据回调的基类
     */
    public void setCallback(B callback) {
        mCallback = callback;
    }


    public BasePresenter setView(V v) {
        this.mView = v;
        this.onAttached();
        return this;
    }

    public <V extends IBaseView> V getView() {
        return (V) mView;
    }

    public void onAttached() {
    }


    /**
     * 具体Presenter网络加载时调用此方法，将网络加载的Subscription，通过IBaseView交由View层管理
     */
//    public void addSubscription(Subscription s) {
//        if (mView != null) {
//            mView.getCompositeSubscription().add(s);
//        }
//    }
//
//
//    public void unSubscribe() {
//        if (mView != null) {
//            mView.getCompositeSubscription().unsubscribe();
//        }
//    }
}
